package com.smt.ejb3.tutoria.client;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.smt.ejb3.tutoria.entitybean.one2one.pk.Customer;
import com.smt.ejb3.tutoria.entitybean.one2one.pk.CustomerNo;
import com.smt.ejb3.tutoria.service.MappingService;

public class CustomerClient {
	public static void main(String[] args) {
		
		Customer cus = new Customer();
		cus.setName("old WANG1");
		
		CustomerNo cusNo = new CustomerNo();
		cusNo.setSn("sun1234567");
		cusNo.setCustomer(cus);
		cus.setCustNo(cusNo);
	
		
		try {
			InitialContext ctx = new InitialContext();

			MappingService service = (MappingService) ctx
					.lookup("MappingServiceImpl/remote");
			/* Save customer */
//			service.saveCustomer(cus);
			/* Find customer */
//			Customer cust = service.findCustomer(1);
//			System.out.println(cust);
			/* Find customerNo */
			CustomerNo custNo = service.findCustomerNo(1);
			System.out.println(custNo.getCustomer().getName());
		} catch (NamingException ex) {
			ex.printStackTrace();
		}
	}
}
